$(function(){
	$('#tt').datagrid({
		url:'/comment/getListPage'
	});
	
});

function doAdd(){
	$('#addForm').form('clear');
	
//	$('#versionId').attr("disabled", false);
//	$('#heartfileId').attr("disabled", false);
	$('#mark').validatebox({ 
		required:true 
	});
	
	$('#addWin').window('open');
}

function doEdit(){
	var record = $('#tt').datagrid('getSelected');
	if(record==null||record==''){
		$.messager.alert("提示", "请先选择一条记录");
		return;
	}
	
	$('#idId').val(record.id);
	$('#mark').val(record.mark);
	$('#comment').val(record.comment);
	
	$('#mark').validatebox({ 
		required:false 
	});
	
	$('#addWin').window('open');
}

function doDel(){
	var rows = $("#tt").datagrid("getSelections");
    if (rows&&rows.length>0){
    	var arrayId = [];
    	for(var i=0;i<rows.length;i++){
    		arrayId.push(rows[i].id);
    	}
    	var ids = arrayId.join(",");
	    showConfirm(market.content.title, market.content.confirm, function(){
		  $.post('/comment/delete',{ids:ids}, function(data) {
		  	if (data.return_code == '1') {
				top.showMsg(market.content.title, data.return_msg, alert);
				$("#tt").datagrid('reload');
				$('#tt').datagrid('clearSelections');
			} else {
				$.messager.alert(market.content.title, data.return_msg);
			}
		  });
	   });
    } else {
    	showMsg(market.content.title, market.content.tips, alert);
    }
}

function doSearch(){
	var smark=$('#smark').val();
	var scomment=$('#scomment').val();
	$('#tt').datagrid({
		url:'/comment/getListPage',
		queryParams:{
			mark:smark,
			comment:scomment
		}
	});
	$('#tt').datagrid('unselectAll');
}

function save(){
	var id=$('#idId').val();
	var url='/comment/update';
	if(id==null||id==''){
		url='/comment/save';
	}
	
	$('#addForm').form('submit',{
		url : url,
		onSubmit : function() {
			var flag = $(this).form('validate');
			if (!flag) {
				return flag;
			}
			showProcess(true, market.content.title, market.content.submitting);
			return true;
		},
		success : function(data) {
			showProcess(false);
			var data = eval('(' + data + ')');
			if (data.return_code == '1') {
				$("#addWin").window('close');
				$("#tt").datagrid('reload');
				$('#tt').datagrid('unselectAll');
			} else {
				$.messager.alert(market.content.title, data.return_msg);
			}
		},
		onLoadError : function() {
			showProcess(false);
			$.messager.alert(market.content.title, market.content.networkError);
		}
	});
}

function doImport() {
	$('#uploadForm').form(
	    'submit',
	    {
			url : '/comment/importExcel',
			onSubmit : function() {
				var excelFile = $('#excelFile').val();
				if (excelFile.lastIndexOf('.xls') < 0&&excelFile.lastIndexOf('.xlsx') < 0) {
					top.showMsg(market.content.title, '上传文件必须为excel文件', alert);
					return false;
				}
				return $(this).form('enableValidation').form('validate');
			},
			success : function(data) {
				showProcess(false);
				var data = eval("(" + data + ")");
				if (data.return_code == '1') {
					top.showMsg(market.content.title, data.return_msg, alert);
					$("#tt").datagrid('reload');
				}else if(data.return_code == '0'){
					$.messager.alert(market.content.title, data.return_msg);
				} else {
					$.messager.alert(market.content.title, data.return_msg);
				}
			},
			onLoadError : function() {
				showProcess(false);
				$.messager.alert(market.content.title, market.content.networkError);
			}
		}); 
}

function cancel(){
	$('#addWin').window('close');
}

function formatUsed(value){
	if(value==1){
		return '已取';
	}else{
		return '未取';
	}
}